package com.clip.dao;
// default package

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.springframework.stereotype.Repository;

import com.clip.entity.ContactType;

@Repository
public class ContactTypeDAO extends BasicDao  {
    private static final Log log = LogFactory.getLog(ContactTypeDAO.class);
	//property constants
	public static final String TYPENAME = "typename";



    
    public void save(ContactType transientInstance) {
        log.debug("saving ContactType instance");
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(ContactType persistentInstance) {
        log.debug("deleting ContactType instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public ContactType findById( java.lang.Integer id) {
        log.debug("getting ContactType instance with id: " + id);
        try {
        	ContactType instance = (ContactType) getSession().get(ContactType.class, id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(ContactType instance) {
        log.debug("finding ContactType instance by example");
        try {
            List results = getSession().createCriteria(ContactType.class).add(Example.create(instance)).list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding ContactType instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from ContactType as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByTypename(Object typename
	) {
		return findByProperty(TYPENAME, typename
		);
	}
	

	public List findAll() {
		log.debug("finding all ContactType instances");
		try {
			String queryString = "from ContactType";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	public Query getQuery(String hql){
		return this.getSession().createQuery(hql);
	}
    public ContactType merge(ContactType detachedInstance) {
        log.debug("merging ContactType instance");
        try {
            ContactType result = (ContactType) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(ContactType instance) {
        log.debug("attaching dirty ContactType instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(ContactType instance) {
        log.debug("attaching clean ContactType instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}